package chun.chun1;

import java.sql.*;

public class DBtext {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/library_management?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String username = "root";
        String password = "qwerqwer1234";
        String sql = "SELECT id, email FROM user WHERE username = ? AND password = ?";

        int id = 0;
        String email = null;

        try (Connection conn = DriverManager.getConnection(url, username, password);
             PreparedStatement prep = conn.prepareStatement(sql)) {

            prep.setString(1, "admin");
            prep.setString(2, "admin123");

            try (ResultSet rs = prep.executeQuery()) {
                if (rs.next()) {
                    id   = rs.getInt("id");
                    email = rs.getString("email");
                } else {
                    System.out.println("用户名或密码错误，未查到记录。");
                }
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }

        System.out.println("id   = " + id);
        System.out.println("email= " + email);
    }
}